const Base = require('./base.js');
const { think } = require('thinkjs');

module.exports = class extends Base {
  async listAction() {
    const page = this.get('page') || 1;
    const size = this.get('size') || 20;
    const model = this.model('apply');

    const query = this.get()
    delete query.page
    delete query.size

   
    const data = await model.alias('a').join({
      table: 'user',
      join: 'inner',
      as: 'c', // 表别名
      on: ['user_id', 'id'] //ON 条件
    }).join({
      table: 'figure',
      join: 'left',
      as: 'd',
      on: ['figture', 'id']
    }).where(query).field("c.nickname, d.company_name as figure_company, d.name as figure_name , d.position as figure_position, a.*, d.has_contact").order(['id DESC']).page(page, size).countSelect();
    return this.success(data);
  }

  async listAllAction() {
    const model = this.model('apply');
    let data = await model.where(filter).order(['id DESC']).select();
    return this.success(data);
  }

  async putAction(){
    const id = this.post('id');
    const status = this.post('status');
    const model = this.model('apply');
    await model.where({id: id}).update({
      status: status
    });
    return this.success();
  }

};
